package com.woniu.mapper;

import com.woniu.been.entity.TMenu;
import com.woniu.been.entity.vo.TMenuVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface TMenuMapper {
    /*
    * 根据姓名查询权限
    * */
    @Select("SELECT role FROM teachers WHERE teacher_name=#{teacherName}")
    Integer checkRole(String teacherName);
    /*
    * 根据姓名查询相关菜单
    * */
    @Select("select m.* from t_menu m join t_role_menu rm on rm.mid = m.id join t_role r on rm.rid = r.t_role_id join teachers t on r.t_role_id = t.role where t.teacher_name = #{teacherName}")
    List<TMenu> findMenus(String teacherName);

    List<TMenuVo> findAllMenus(TMenuVo tMenuVo);

    @Insert("insert into t_menu(title,route,pid) values(#{title},#{route},#{pid})")
    void insertMenu(TMenu tMenu);

    @Select("update t_menu set title=#{title} where id=#{id}")
    void editMenu(TMenu tMenu);

    @Delete("delete from t_menu where id=#{id}")
    void deleteMenu(Integer id);

    @Delete("delete from t_role_menu where mid=#{id}")
    void deleteRoleMenu(Integer id);

    @Select("select * from t_menu where title=#{title}")
    List<TMenu> selectMenuId(String title);

    @Insert("insert into t_role_menu(rid,mid) values(#{param1},#{param2})")
    void insertRoleMenu(int role, int id);
}
